<?php
/**
 * 用户密码构造函数
 * @param $password
 * @return string
 */
function userPassword($password)
{
    return md5('laoWang' . $password);
}

function userPasswordNew($password, $salt)
{
    return hash_hmac('md5', $password, $salt);
}

/**
 * +----------------------------------------------------------
 * 生成随机字符串
 * +----------------------------------------------------------
 * @param int $length 要生成的随机字符串长度
 * @param string $type 随机码类型：0，数字+大小写字母；1，数字；2，小写字母；3，大写字母；4，特殊字符；-1，数字+大小写字母+特殊字符
 * +----------------------------------------------------------
 * @return string
 * +----------------------------------------------------------
 */
function randString($length = 5, $type = 0)
{
    $arr = array(1 => "0123456789", 2 => "abcdefghijklmnopqrstuvwxyz", 3 => "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 4 => "~@#$%^&*(){}[]|");
    if ($type == 0) {
        array_pop($arr);
        $string = implode("", $arr);
    } elseif ($type == "-1") {
        $string = implode("", $arr);
    } else {
        $string = $arr[$type];
    }
    $count = strlen($string) - 1;
    $code = '';
    for ($i = 0; $i < $length; $i++) {
        $code .= $string[rand(0, $count)];
    }
    return $code;
}

/**
 * 设置用户 Session
 * @param $username @登录账号（用户电话）
 * @param $userid @用户ID
 * @param $name @用户名字
 * @param $email @用户邮箱
 */
function setSession($user_info)
{

    session('userid', $user_info['id']);
    session("name", $user_info['username']);
}


/**
 * 获取 Seeion
 * @return mixed
 */
function getSession()
{
    $userInfo['userid'] = session("userid");
    $userInfo['name'] = session("name");
    return $userInfo;
}



